﻿using Furion.DatabaseAccessor;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Queer.Util.Helper
{
    /// <summary>
    /// 仓储方法扩展
    /// </summary>
    public static class IRepositoryHelper
    {
        #region 真实删除

        /// <summary>
        /// 批量删除，且数据存在才根据主键删除（立即提交）
        /// </summary>
        public async static Task BatchDeleteAsync<T>(this IRepository<T> Db, ICollection<long> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.DeleteNowAsync(id);
            };
        }

        /// <summary>
        /// 批量删除，且数据存在才根据主键删除（立即提交）
        /// </summary>
        public async static Task BatchDeleteAsync<T>(this IRepository<T> Db, ICollection<long?> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.DeleteNowAsync(id);
            };
        }

        /// <summary>
        /// 批量删除，且数据存在才根据主键删除（立即提交）
        /// </summary>
        public async static Task BatchDeleteAsync<T>(this IRepository<T> Db, ICollection<string> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.DeleteNowAsync(id.ParseToLong());
            };
        }

        #endregion

        #region 伪删除

        /// <summary>
        /// 批量伪删除（立即提交）
        /// </summary>
        public async static Task BatchFakeDeleteAsync<T>(this IRepository<T> Db, ICollection<string> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.FakeDeleteNowAsync(id.ParseToLong());
            };
        }

        /// <summary>
        /// 批量伪删除（立即提交）
        /// </summary>
        public async static Task BatchFakeDeleteAsync<T>(this IRepository<T> Db, ICollection<long> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.FakeDeleteNowAsync(id);
            };
        }

        /// <summary>
        /// 批量伪删除（立即提交）
        /// </summary>
        public async static Task BatchFakeDeleteAsync<T>(this IRepository<T> Db, ICollection<long?> ids) where T : class, IPrivateEntity, new()
        {
            foreach (var id in ids)
            {
                await Db.FakeDeleteNowAsync(id);
            };
        }

        #endregion
    }
}